<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品系统</el-breadcrumb-item>
      <el-breadcrumb-item>添加品牌</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-form ref="form" :model="brand" label-width="80px">
        <el-form-item label="品牌名称">
          <el-input v-model="brand.name"></el-input>
        </el-form-item>
        <el-form-item label="品牌首字母">
          <el-input v-model="brand.firstLetter"></el-input>
        </el-form-item>
        <el-form-item label="品牌logo">
          <el-upload
            class="upload-demo"
            :with-credentials="true"
            action="http://localhost:8989/admin/bzBrand/upload"
            name="mf"
            :file-list="fileList"
            list-type="picture-card"
            :multiple="false"
            :limit="1"
            :on-success="handleOnSuccess"
            :on-exceed="handleOnExceed"
            accept=".png"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="排序">
          <el-input v-model="brand.sort"></el-input>
        </el-form-item>
        <el-form-item label="是否显示">
          <el-radio-group v-model="brand.showStatus">
            <el-radio label="1" >显示</el-radio>
            <el-radio label="0">不显示</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="品牌故事">
          <el-input type="textarea" v-model="brand.brandStory"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>

</template>

<script>
export default {
  name: "AddBrand",
  data(){
    return {
      brand:{},
      fileList:[]
    }
  },
  methods:{
    onSubmit(){
      this.axios.post("/admin/bzBrand",this.brand)
        .then(resp=>{
          this.$message({
            message:"添加成功"
          })
          this.$router.push("/product/brand");
        })
    },
    handleOnSuccess(resp,file){
      this.brand.logo=resp.data;
    },
    handleOnExceed(file,fileList){
      this.$message({
        type:"error",
        message:"文件数量不能超过1"
      })
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-top:20px
  }
  .el-row{
    margin: 10px 0;
  }
</style>
